﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CatSimulator
{
    public partial class FormBase : Form
    {
        public FormBase()
        {
            InitializeComponent();
        }
        public WizardController controller = null;

        #region 函数
        /// <summary>
        /// 自定义函数
        /// </summary>
        public void DisableButton()
        {
            if (this.controller == null)
                return;
            if (this.controller.IsFirstForm)
            {
                this.buttonPrev.Enabled = false;
            }
            else
            {
                this.buttonPrev.Enabled = true;
            }
            if (this.controller.IsLastForm) //如果是向导的最后一个页面，显示“完成”
            {
                this.buttonNext.Text = "完成";
            }
            else    //否则显示“下一步”
            {
                this.buttonNext.Text = "下一步";
            }
        }


        //由“每一步FormStep1，FormStep2…”的界面 具体实现
        protected virtual bool UpdateInfo()
        {
            return true;
        }

        protected virtual void GoNext()
        {
            if (UpdateInfo())
            {
                if (this.controller.IsLastForm) //如果是向导的最后一个页面，则调用“FinishWizard()”
                {
                    controller.FinishWizard();
                    this.Visible = false;
                }
                else//如果是向导的最后一个页面，则调用“GoNext()”
                {
                    controller.GoNext();
                }

            }

        }
        protected virtual void GoPrev()
        {
            UpdateInfo();
            controller.GoPrev();
        }
        //protected virtual void Finish()
        //{
        //    UpdateInfo();
        //    controller.FinishWizard();
        //    this.Visible = false;
        //}
        protected virtual void Cancel()
        {
            //this.controller.info = null;
            this.Close();
        }
        #endregion

        #region 界面控件事件
        /// <summary>
        /// 界面控件事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonPrev_Click(object sender, EventArgs e)
        {
            GoPrev();
        }
        private void buttonNext_Click(object sender, EventArgs e)
        {
            GoNext();
        }

        //private void buttonFinish_Click(object sender, EventArgs e)
        //{
        //    Finish();
        //}
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Cancel();
        }
        #endregion

    }
}
